#include "main/utils.h"
using namespace std;

int minSubArray(const vector<int> &array, const int &k) {
  int begin = 0, end = 0;
  int sum = array[0];
  int min_len = INT_MAX;
  int cur_len = 1;
  while (begin <= end && end < array.size()) {
    if (sum < k) {
      sum += array[++end];
      ++cur_len;
    } else {
      sum -= array[begin++];
      --cur_len;
      if (cur_len < min_len) {
        min_len = cur_len;
      }
    }
  }
  return min_len == INT_MAX ? 0 : min_len;
}

int main() {
  vector<int> vec = {5, 1, 4, 3};
  int k = 8;
  int ret = minSubArray(vec, k);
  cout << "The minimum length of array is: " << ret << endl;

  return 0;
}
